package com.soft.dao;

import com.soft.entity.OrderRefundRecord;
import com.soft.util.Connect;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName OrderRefundRecordDao
 * @Description 退货处理记录接口
 * @Date 2021/5/27 11:47
 * @Version 1.0
 */
public class OrderRefundRecordDao {

    Class<OrderRefundRecord> orderRefundRecordClass;

    public OrderRefundRecordDao() {
        orderRefundRecordClass = OrderRefundRecord.class;
    }

    /**
     * @Author: 孔子雄
     * @Description: 根据id获取退款记录
     * @DateTime: 2021/5/27 16:34
     * @Params: id：退款记录的编号
     * @Return: OrderRefundRecord实体类
     */
    public OrderRefundRecord get(int id) {
        List<Object> param = new ArrayList<>();
        param.add(id);

        String sql = "select * from orderRefundRecord where id=?";
        return Connect.getInstance().queryObject(sql, param, orderRefundRecordClass);
    }

    /**
     * @Author: 孔子雄
     * @Description: 根据orderId获取退款记录
     * @DateTime: 2021/5/27 16:40
     * @Params: orderId：订单编号
     * @Return: OrderRefundRecord实体类
     */

    public OrderRefundRecord getByOrderId(int orderId) {
        List<Object> param = new ArrayList<>();
        param.add(orderId);

        String sql = "select * from orderRefundRecord where orderId=?";
        return Connect.getInstance().queryObject(sql, param, orderRefundRecordClass);
    }

    /**
     * @Author: 孔子雄
     * @Description: 更新OrderRefundRecord
     * @DateTime: 2021/5/27 17:13
     * @Params: ord:OrderRefundRecord实体
     * @Return: boolean
     */
    public boolean updateOrderRefundRecord(OrderRefundRecord ord) {
        List<Object> param = new ArrayList<Object>();
        param.add(ord.getOrderId());
        param.add(ord.getSum());
        param.add(ord.getDetail());
        param.add(ord.getStatus());
        param.add(ord.getId());

        String sql = "update orderRefundRecord set orderId=?, sum=?, detail=?, status=? where id=?";

        int flag = Connect.getInstance().execute(sql, param);
        if (flag != 0) {
            return true;
        }
        return  false;
    }

    /**
     * @author kongz 2021/6/9 11:08
     * @description 新建退货记录
     * @param ord 退货记录实体
     * @return boolean
     */
    public boolean insert(OrderRefundRecord ord) {
        List<Object> param = new ArrayList<>();
        param.add(ord.getOrderId());

        String sql = "insert into orderrefundrecord(orderId) value(?)";

        if (Connect.getInstance().execute(sql, param) != 0)
            return true;
        return false;
    }
}
